<?php
namespace app\admin\controller;
use app\admin\controller\Base;
class Featured extends Base{
    
    public function index(){
        $types=config("featured.featured_type");
        $type=input("get.type",0,"intval");
        $results=model("Featured")->getFeaturedsByType($type);
       return $this->fetch("",[
         "types"=>$types,
         "results"=>$results,
     ]);
    }
    
    public function add(){
        $types=config("featured.featured_type");
        return $this->fetch("",[
            "types"=>$types,
        ]);
    }
    
    public function save(){
        if(!request()->isPost()){
            $this->error("非法访问");
        }
        $data=input("post.");
        $validate=validate("Featured");
        if(!$validate->scene("add")->check($data)){
            $this->error($validate->getError());
         }
        //添加
         
         $id=model("Featured")->add($data);
         if($id) {
	$this->success('添加成功',url('featured/index'));
             }else{
	$this->error('添加失败');
              }
    }
    //状态
    public function status(){
        if(!request()->isGet()){
           $this->error("非法访问");
        }
        $data=input("get.");
        $validate=validate("Featured");
        if(!$validate->scene("status")->check($data)){
            $this->error($validate->getError());
        }
        
        //更新状态
        $res=model("Featured")->save(["status"=>$data['status']],["id"=>$data['id']]);
        if($res){
            $this->success("更新成功");
        }else{
             $this->error("更新失败");
        }
        
        
    }
}

